package com.wk.service.implement;

import com.wk.dao.Itemdao;
import com.wk.pojo.Course_exam;
import com.wk.pojo.Coursetype;
import com.wk.pojo.Error_book;
import com.wk.pojo.Item_type;
import com.wk.service.Itemservice;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.util.List;
import java.util.Map;

/**
 * @program: thesis
 * @description: 学生的试题库
 * @author: 王侃
 * @create: 2020-02-23 09:38
 **/
@Service
public class Itemserviceimpl implements Itemservice {

    @Autowired
    Itemdao itemdao;

    @Override
    public List<Item_type> selectbyitemtype() {
        return itemdao.selectbyitemtype();
    }

    @Override
    public List<Coursetype> selectbyallcoursetype() {
        return itemdao.selectbyallcoursetype();
    }

    @Override
    public List<Map<String, Object>> selectbyitemexam(Integer type_id) {
        return itemdao.selectbyitemexam(type_id);
    }

    @Override
    public List<Course_exam> selectbychapterexam(Integer coursetype_id) {
        return itemdao.selectbychapterexam(coursetype_id);
    }

    @Override
    public List<Course_exam> selectbymyitems(Integer type_id, Integer user_id) {
        return itemdao.selectbymyitems(type_id, user_id);
    }

    @Override
    public void insertintomyitem(Course_exam exam) {
        itemdao.insertintomyitem(exam);
    }

    @Override
    public void updatebyitemtype(Integer id) {
        itemdao.updatebyitemtype(id);
    }

    @Override
    public void updatebymyitemtest(Course_exam exam) {
        itemdao.updatebymyitemtest(exam);
    }

    @Override
    public void updatebymyitemessay(Course_exam exam) {
        itemdao.updatebymyitemessay(exam);
    }

    @Override
    public void deletebyitemtype(Integer id) {
        itemdao.deletebyitemtype(id);
    }

    @Override
    public void insertintomyerrorbook(Course_exam exam) {
        itemdao.insertintomyerrorbook(exam);
    }

    @Override
    public List<Map<String, Object>> selectbymyerrorbook(Integer user_id) {
        return itemdao.selectbymyerrorbook(user_id);
    }

    @Override
    public void deletebymyerrorbook(Integer id) {
        itemdao.deletebymyerrorbook(id);
    }

    @Override
    public List<Course_exam> selectbyitems_word(Integer type_id) {
        return itemdao.selectbyitems_word(type_id);
    }

    @Override
    public List<Error_book> selectbymyerrorbook_word(Integer user_id) {
        return itemdao.selectbymyerrorbook_word(user_id);
    }

    @Override
    public List<Course_exam> selectbyitemschapter_word(Integer coursetype_id) {
        return itemdao.selectbyitemschapter_word(coursetype_id);
    }

    @Override
    public void exportword(XWPFDocument document, HttpServletResponse response, String fileName) throws Exception {
        response.setHeader("Content-Disposition","attachment;fileName="+ new String(fileName.getBytes("utf-8"),"iso8859-1"));
        response.setContentType("application/msword");
        OutputStream os = response.getOutputStream();
        document.write(os);
        os.flush();
        os.close();
    }
}
